package com.ruoyi.web.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.order.domain.MesManufacturer;
import com.ruoyi.order.service.IMesManufacturerService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.MesProdcutModel;
import com.ruoyi.order.service.IMesProdcutModelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品型号Controller
 * 
 * @author guoxl
 * @date 2025-04-30
 */
@RestController
@RequestMapping("/order/model")
public class MesProdcutModelController extends BaseController
{
    @Autowired
    private IMesProdcutModelService mesProdcutModelService;

    @Autowired
    private IMesManufacturerService mesManufacturerService;

    /**
     * 查询产品型号列表
     */
    @PreAuthorize("@ss.hasPermi('order:model:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesProdcutModel mesProdcutModel)
    {
        startPage();
        List<MesProdcutModel> list = mesProdcutModelService.selectMesProdcutModelList(mesProdcutModel);
        return getDataTable(list);
    }

    /**
     * 导出产品型号列表
     */
    @PreAuthorize("@ss.hasPermi('order:model:export')")
    @Log(title = "产品型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesProdcutModel mesProdcutModel)
    {
        List<MesProdcutModel> list = mesProdcutModelService.selectMesProdcutModelList(mesProdcutModel);
        ExcelUtil<MesProdcutModel> util = new ExcelUtil<MesProdcutModel>(MesProdcutModel.class);
        util.exportExcel(response, list, "产品型号数据");
    }

    /**
     * 获取产品型号详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:model:query')")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") Long modelId)
    {
        AjaxResult ajax = AjaxResult.success();
        if (modelId > 0){
            MesProdcutModel mesProdcutModel = mesProdcutModelService.selectMesProdcutModelByModelId(modelId);
            ajax.put(AjaxResult.DATA_TAG, mesProdcutModel);
        }
        //获取所有有效厂商列表
        MesManufacturer mesManufacturer = new MesManufacturer();
        mesManufacturer.setStatus("0");
        List<MesManufacturer> mesManufacturerList = mesManufacturerService.selectMesManufacturerList(mesManufacturer);
        ajax.put("manufacturerOptions", mesManufacturerList);
        return ajax;
    }

    /**
     * 新增产品型号
     */
    @PreAuthorize("@ss.hasPermi('order:model:add')")
    @Log(title = "产品型号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesProdcutModel mesProdcutModel)
    {
        return toAjax(mesProdcutModelService.insertMesProdcutModel(mesProdcutModel));
    }

    /**
     * 修改产品型号
     */
    @PreAuthorize("@ss.hasPermi('order:model:edit')")
    @Log(title = "产品型号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesProdcutModel mesProdcutModel)
    {
        return toAjax(mesProdcutModelService.updateMesProdcutModel(mesProdcutModel));
    }

    /**
     * 删除产品型号
     */
    @PreAuthorize("@ss.hasPermi('order:model:remove')")
    @Log(title = "产品型号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelIds}")
    public AjaxResult remove(@PathVariable Long[] modelIds)
    {
        return toAjax(mesProdcutModelService.deleteMesProdcutModelByModelIds(modelIds));
    }
}
